package com.voole.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.voole.dao.BaseDao;
import com.voole.dao.SysAuthorityDao;
import com.voole.dao.SysCatalogDao;
import com.voole.entity.SysAuthority;
import com.voole.entity.SysCatalog;
import com.voole.service.ISysAuthorityService;
import com.voole.service.ISysCatalogService;

@Service
public class SysCatalogServiceImpl implements ISysCatalogService {

	@Autowired
	BaseDao baseDao;
	@Autowired
	SysCatalogDao sysCatalogDao;
	
	/**
	 * 获取所有二级菜单（左侧主要菜单）
	 */
	public List<SysCatalog> getList() throws Exception {
		return sysCatalogDao.getList();
	}
	
	/**
	 * 根据 fatherId（顶侧菜单Id）
	 * 获取所有二级菜单（左侧主要菜单）
	 */
	public List<SysCatalog> getListByAuthorityId(Integer authorityId) throws Exception {
		return sysCatalogDao.getListByAuthorithId(authorityId);
	}

	/**
	 * 删除二级菜单, 以及下属 所有三级菜单(sys_resource)、功能菜单(sys_action)
	 */
	public Integer delSysCatalogAndChild(Integer catalogId) throws Exception {
		sysCatalogDao.delSysCatalog(catalogId);
		return null;
	}

	/**
	 * 新增 二级菜单
	 * @return id
	 */
	public Integer addCatalog(String catalogName, Integer authorityid, Integer sort, Integer status) throws Exception {
		SysCatalog sc = new SysCatalog();
		sc.setCatalogname(catalogName);
		sc.setSort(sort);
		sc.setStatus(status);
		sc.setAuthorityid(authorityid);
		sysCatalogDao.addSysCatalog(sc);
		return sc.getId();
	}
	
	

}
